package com.LeeCode;

/**
 * H 指数 II
 */

public class Code275 {
    public static void main(String[] args) {
        int[] citations = {0};
        System.out.println(new Code275().hIndex(citations));
    }

    public int hIndex(int[] citations) {
        int left = 0, right = citations.length + 1;
        int n = citations.length;
        while (left + 1 < right) {
            int mid = left + (right - left) / 2;
            if (citations[n - mid] >= mid)
                left = mid;  // 求上界写法，注意和求下界的区别
            else
                right = mid;
        }
        return left;
    }

}
